unit Drops;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs;

const
  MaxUnlDataSize = 256;

type
  TUnlData = class(TObject)
  private
    FData: array [0..MaxUnlDataSize-1] of byte;
    FLength: Integer;
  public
    function Compare(const NewData: PByte; const NewLength: Integer): Boolean;
    property Length: Integer read FLength write FLength;
  end;

  TDrops = class(TObject)
  private
    FAddress: Byte;
    FQuery: TUnlData;
    FResponse: TUnlData;
  public
    constructor Create;
    function CompareQuery(Data: PByte; Length: Integer): Boolean;
    function CompareResponse(Data: PByte; Length: Integer): Boolean;
    property Address: Byte read FAddress write FAddress;
    property Query: TUnlData read FQuery write FQuery;
    property Response: TUnlData read FResponse write FResponse;
  end;

implementation

{
*********************************** TUnlData ***********************************
}
function TUnlData.Compare(const NewData: PByte; const NewLength: Integer):
    Boolean;
var
  i: Integer;
  p: ^Byte;
begin
  p := Pointer(NewData);
  Result := True;

  if Length <> NewLength then begin
    Length := NewLength;
    Result := False;
  end;

  for i := 0 to Length - 1 do begin
    if FData[i] <> p^ then begin
      Result := False;
      Break;
    end;
    inc(p);
  end;

  while i < Length do begin
    FData[i] := p^;
    inc(p);
    inc(i);
  end;
end;

{
************************************ TDrops ************************************
}
constructor TDrops.Create;
begin
  inherited Create;

  Query.Length := 0;
  Response.Length := 0;
end;

function TDrops.CompareQuery(Data: PByte; Length: Integer): Boolean;
begin
  Result := Query.Compare(Data, Length);
end;

function TDrops.CompareResponse(Data: PByte; Length: Integer): Boolean;
begin
  Result := Response.Compare(Data, Length);
end;

end.
